//
//  LCShengJingTextViewController+LCAVPlay.m
//  JKFuYinProject
//
//  Created by admin on 2018/1/8.
//  Copyright © 2018年 LC. All rights reserved.
//

#import "LCShengJingTextViewController+LCAVPlay.h"

@implementation LCShengJingTextViewController (LCAVPlay)

-(void)creareAVPlay{
    // 安装通知
    [self setupNotifications];
}

#pragma mark - 通知处理 -
// 安装通知
- (void)setupNotifications {
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotification:) name:@"PUSHPLAYPAGE" object:nil];
    
    // 1. 安装播放状态发生变化的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(musicPlayerPlayingSongDidChangedNotification:) name:LCMusicPlayerPlayingSongDidChangedNotification object:_LCPlayer];
    
}

// 卸载通知
- (void)teardownNotifications {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark - 通知处理回调
///跳转到播放页
-(void)receiveNotification:(NSNotification *)notification{

    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"LCPlayStoryboard" bundle:nil];
    UIViewController *controller = [sb instantiateInitialViewController];
    [self presentViewController:controller animated:YES completion:nil];
}


///跳转到相关播放页
-(void)musicPlayerPlayingSongDidChangedNotification:(NSNotification *)notification{
    JKSongsMessStatus *playingSong = notification.userInfo[kMusicPlayerPlayingSong];
    NSString *tabNameStr = playingSong.title;
    tabNameStr = [tabNameStr substringWithinBoundsLeft:@"约" right:@"("];
    tabNameStr = [tabNameStr stringByReplacingOccurrencesOfString:@"新约" withString:@""];
    tabNameStr = [tabNameStr stringByReplacingOccurrencesOfString:@"旧约" withString:@""];
    
    if (tabNameStr != nil) {
        self.nameStr = tabNameStr;
        self.tabNameLabel.attributedText = [[NSAttributedString alloc] initWithString:tabNameStr];
        [self.nameBtn setTitle:tabNameStr forState:UIControlStateNormal];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.nameBtn setTitle:tabNameStr forState:UIControlStateNormal];
        });
    }
    NSString *countStr = playingSong.title;
    countStr = [countStr substringWithinBoundsLeft:@"第" right:@"章"];
    self.numLabel.text = [NSString stringWithFormat:@"第 %@ 章", countStr];
    [self.countBtn setTitle:[NSString stringWithFormat:@"%@", countStr] forState:UIControlStateNormal];
    
    self.bibleTableViewController.currentRow = 0;
    [self.bibleTableViewController.selectedData removeAllObjects];
    [self.bibleTableViewController.indexPathArr removeAllObjects];
    if (self.bibleTableViewController.lrcArray.count > 0) {
        [self.bibleTableViewController.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
    }
}

@end
